package vip.xiaonuo.supplier.modular.finance.account.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.finance.account.entity.SupplierAccount;
import vip.xiaonuo.supplier.modular.finance.account.param.SupplierAccountAddParam;
import vip.xiaonuo.supplier.modular.finance.account.param.SupplierAccountEditParam;
import vip.xiaonuo.supplier.modular.finance.account.param.SupplierAccountIdParam;
import vip.xiaonuo.supplier.modular.finance.account.param.SupplierAccountPageParam;
import vip.xiaonuo.supplier.modular.finance.account.service.SupplierAccountService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 结算账户控制器
 *
 * @author Mr.wu
 * @date  2025/03/17 17:17
 */
@Tag(name = "结算账户控制器")
@RestController
@Validated
public class SupplierAccountController {

    @Resource
    private SupplierAccountService supplierAccountService;

    /**
     * 获取结算账户分页
     *
     * @author Mr.wu
     * @date  2025/03/17 17:17
     */
    @Operation(summary = "获取结算账户分页")
    @SaCheckPermission("/supplier/finance/account/page")
    @GetMapping("/supplier/finance/account/page")
    public CommonResult<Page<SupplierAccount>> page(SupplierAccountPageParam supplierAccountPageParam) {
        return CommonResult.data(supplierAccountService.page(supplierAccountPageParam));
    }

    /**
     * 添加结算账户
     *
     * @author Mr.wu
     * @date  2025/03/17 17:17
     */
    @Operation(summary = "添加结算账户")
    @CommonLog("添加结算账户")
    @SaCheckPermission("/supplier/finance/account/add")
    @PostMapping("/supplier/finance/account/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierAccountAddParam supplierAccountAddParam) {
        supplierAccountService.add(supplierAccountAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑结算账户
     *
     * @author Mr.wu
     * @date  2025/03/17 17:17
     */
    @Operation(summary = "编辑结算账户")
    @CommonLog("编辑结算账户")
    @SaCheckPermission("/supplier/finance/account/edit")
    @PostMapping("/supplier/finance/account/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierAccountEditParam supplierAccountEditParam) {
        supplierAccountService.edit(supplierAccountEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除结算账户
     *
     * @author Mr.wu
     * @date  2025/03/17 17:17
     */
    @Operation(summary = "删除结算账户")
    @CommonLog("删除结算账户")
    @SaCheckPermission("/supplier/finance/account/delete")
    @PostMapping("/supplier/finance/account/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierAccountIdParam> supplierAccountIdParamList) {
        supplierAccountService.delete(supplierAccountIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取结算账户详情
     *
     * @author Mr.wu
     * @date  2025/03/17 17:17
     */
    @Operation(summary = "获取结算账户详情")
    @SaCheckPermission("/supplier/finance/account/detail")
    @GetMapping("/supplier/finance/account/detail")
    public CommonResult<SupplierAccount> detail(@Valid SupplierAccountIdParam supplierAccountIdParam) {
        return CommonResult.data(supplierAccountService.detail(supplierAccountIdParam));
    }
}
